package com.cvo.scrumtoolkit.client.controller;


import com.cvo.scrumtoolkit.client.pannels.MenuPanel;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.RootPanel;

public class HistoryManager {
	
	Controller controler;
	static String vieuuw;
	MenuPanel mp = new MenuPanel();

	public HistoryManager(final Controller controler){
		this.controler = controler;
		
		 History.addValueChangeHandler(new ValueChangeHandler<String>() {
		      public void onValueChange(ValueChangeEvent<String> event) {
		        String historyToken = event.getValue();
		      
		        String[] tokens = historyToken.split("/");
		       
		        //TODO: error handling when no 3 parameters 
		        
		        View view = View.getByShortname(tokens[0]);
		        vieuuw=(tokens[0]);
		        mp.veranderkleur(vieuuw);
		        RootPanel.get("menuContainer").clear();
		        RootPanel.get("menuContainer").add(mp);
		         String projectId = tokens[1];
		        String sprintId = tokens[2];
		        
		        
		        controler.changeView(view, projectId, sprintId);
		      }
		      
		      
		      
		  });
	}
	
	public static void gotoUrl(String token){
		History.newItem(token);
	}
	
	
	public static String getVieuuw() {
		return vieuuw;
	}
	
	
	 



}
